<?php

namespace App\Http\Middleware;

use App\Traits\Admin\SuccessOrFailure;
use Closure;
use Daijulong\LaravelRoles\Permission;
use Illuminate\Support\Facades\Auth;

class WorkerCheck
{
    use SuccessOrFailure;

    public function handle($request, Closure $next)
    {

        if (!Auth::check()) {
            return redirect()->route('guest.login');
        }
        if (!Auth::user()->enabled) {
            return response($this->failure('账号未授权或已被禁用'));
        }
        Permission::loadConfigAndSetUser(Auth::user());
        return $next($request);
    }
}
